import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/a.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/utils/cash_utils.dart';
import 'package:finance_app/src/widgets/common/tag_widget.dart';
import 'package:finance_app/src/widgets/select/mixin/radio_mixin.dart';
import 'package:flutter/material.dart';

import 'mixin/check_box_mixin.dart';

class TransactionRecordCheckBoxItem = TransactionRecordRadioItem
    with CheckBoxMixin;

class TransactionRecordRadioItem extends StatelessWidget with RadioMixin {
  final VoidCallback onTap;
  final String tag;
  final String name;
  final String time;
  final num amount;
  final bool overdueDay;
  final String billNumber;
  final String status;
  final String currencyCode;
  final bool isUnpaid;
  final bool isSelect;

  TransactionRecordRadioItem(
      {Key key,
      this.onTap,
      this.tag,
      this.isUnpaid,
      this.overdueDay,
      this.name,
      this.billNumber,
      this.time,
      this.status,
      this.amount,
      this.currencyCode,
      this.isSelect})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final bool isReduce = (tag == 'Money-Out' ||
        tag == 'Expense' ||
        tag == 'PO' ||
        tag == 'Bill');
    final bool isHideOperation = tag == 'Transfer';
    return Padding(
      padding: EdgeInsets.only(
        bottom: getDp(10),
      ),
      child: PressedOpacityButton(
        onPressed: onTap,
        padding: EdgeInsets.symmetric(vertical: getDp(28)),
        color: Colors.white,
        disabledColor: Colors.white,
        border: Border(
            bottom: BorderSide(
          color: aceGrayColor,
          width: 0.5,
        )),
        child: Row(
          children: [
            Container(
              width: getDp(75),
              alignment: Alignment.center,
              child: buildSelectWidget,
            ),
            Expanded(
                child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  name ?? '',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: getSp(16),
                    height: 14 / 16,
                  ),
                ),
                if (billNumber != null)
                  Padding(
                    padding: EdgeInsets.only(
                      bottom: getDp(6),
                    ),
                    child: Text(
                      '${tag.replaceAll('\n', '')} NO:$billNumber',
                      style: TextStyle(
                        fontWeight: FontWeight.w400,
                        fontSize: getSp(14),
                      ),
                    ),
                  ),
                Text(
                  '${tag == 'Expense' && isUnpaid == true ? '${S.current.due}: ' : '${S.current.date}: '}$time',
                  style: TextStyle(
                    fontWeight: FontWeight.w400,
                    fontSize: getSp(14),
                  ),
                ),
              ],
            )),
            Container(
              constraints: BoxConstraints(maxWidth: getDp(140)),
              child: Padding(
                padding: EdgeInsets.only(right: getDp(19), left: getDp(10)),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    if (isHideTag())
                      Container()
                    else if (status != null)
                      Container(
                        margin: EdgeInsets.only(
                          bottom: getDp(10),
                        ),
                        child: status == 'Overdue'
                            ? RedTagWidget(
                                content: status,
                              )
                            : NormalRedTagWidget(
                                content: status,
                              ),
                      ),
                    if (overdueDay == true)
                      Container(
                        margin: EdgeInsets.only(
                          bottom: getDp(10),
                        ),
                        child: RedTagWidget(
                          content: 'Overdue',
                        ),
                      ),
                    Text.rich(
                      TextSpan(
                          text: isHideOperation
                              ? ''
                              : isReduce
                                  ? '-'
                                  : '+',
                          style: TextStyle(
                              fontSize: getSp(16),
                              color: CashUtils.getColor(isReduce ? -1 : 1),
                              fontWeight: FontWeight.bold,
                              height: 14 / 12,
                              fontFamily: "DinRoundPro"),
                          children: [
                            TextSpan(
                              text:
                                  ' ${currencyCode ?? 'SGD'} ${CashUtils.ignoreFormatCashAmount(amount)}',
                              style: TextStyle(
                                color: aceBlackColor,
                                fontSize: getSp(16),
                                fontWeight: FontWeight.w700,
                                height: 14 / 16,
                              ),
                            ),
                          ]),
                      textAlign: TextAlign.end,
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  bool isHideTag() {
    return tag == 'Expense' && status == 'Paid' ||
        tag == 'PO' && status == 'Closed' ||
        tag == 'Money-Out' && status == 'Paid' ||
        tag == 'Money-In' && status == 'Paid' ||
        tag == 'Quotation' && status == 'Closed' ||
        tag == 'Invoice' && status == 'Paid' ||
        tag == 'Bill' && status == 'Paid';
  }
}
